package cn.itcast.bos.consumer;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Component;

/**对应applicationContext中的<jms:listener destination="bos_couriersms" ref="queueConsumer1"/>*/
@Component(value="queueConsumer1")
public class CourierSmsConsumer implements MessageListener {

	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage)message;
		try {
			String telephone = mapMessage.getString("telephone");
			String num = mapMessage.getString("num"); // 验证码
			String sendAddres = mapMessage.getString("sendAddres"); // 寄件人地址
			String sendName = mapMessage.getString("sendName"); // 寄件人
			String sendMobile = mapMessage.getString("sendMobile"); // 寄件人电话
			String sendMobileMsg = mapMessage.getString("sendMobileMsg"); // 快递员稍话
			// 内容可以新建一个模板，然后发送新的短信内容即可。
//			SendSmsResponse sendSmsResponse = SmsDemoUtils2.sendSms(telephone, num, sendAddres, sendName, sendMobile, sendMobileMsg);
//			String sendSms = sendSmsResponse.getCode();
			String sendSms = "OK";//这里需要SmsDemoUtils2工具类    我没有，发不了短信
			if(sendSms.equals("OK")){
				// 发送成功
				System.out.println("发送短信成功,手机号：" + telephone);
				System.out.println("速运快递 短信序号："+num+",取件地址："+sendAddres+",联系人："+sendName+",手机:"+sendMobile+"，快递员捎话："+sendMobileMsg+"");
//				QuerySendDetailsResponse querySendDetails = SmsDemoUtils.querySendDetails(sendSmsResponse.getBizId());
//				
//				List<SmsSendDetailDTO> smsSendDetailDTOs = querySendDetails.getSmsSendDetailDTOs();
//				for(QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO :smsSendDetailDTOs){
//					System.out.println("短信内容："+smsSendDetailDTO.getContent());
//				}
			}
		} catch (Exception e) {
			System.out.println("发送短信失败！！！");
			e.printStackTrace();
		}
		
	}

}